package com.cn.crmsystem.controller.businessController;

import com.cn.crmsystem.pojo.Contract;
import com.cn.crmsystem.pojo.Login;
import com.cn.crmsystem.pojo.ResultJson;
import com.cn.crmsystem.service.businessService.ContractService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(value = "合同",tags ="合同接口API" )
public class AllContractController {
    @Autowired
    private ContractService contractService;
    @RequestMapping(value = "/selectAllContract",method = RequestMethod.POST)
    @ApiOperation(value = "查询",notes = "业务员管理员查询",httpMethod = "POST",response = ResultJson.class)
    public ResultJson selectAll(@RequestBody @ApiParam(name = "contract",value = "合同查询") Contract contract){
        return  contractService.selectAll(contract);
    }


    /**
     * 根据ID
     * @param id
     * @return
     */
    @RequestMapping(value = "/selectContract",method = RequestMethod.POST)
    @ApiOperation(value = "根据ID查询",notes = "业务员管理层查询",httpMethod = "POST",response = ResultJson.class)
    public ResultJson select(@ApiParam(name = "id",value = "合同ID") Integer id){
        return contractService.selectContract(id);
    }

    @RequestMapping(value = "/addContract",method = RequestMethod.POST)
    @ApiOperation(value = "新增",notes = "业务员管理层新增",httpMethod ="POST",response = ResultJson.class)
    public ResultJson addContract(@RequestBody
         @ApiParam(name = "contract",value = "新增合同")
         Contract contract){
       // Login login = (Login) SecurityUtils.getSubject().getPrincipal();
        Login login = new Login();
        login.setUser_id(1);
        System.out.println(login);
        System.out.println("新增合同");
        System.out.println(contract.getContract_number());
        System.out.println(contract.getContract_name());
        return contractService.addContract(contract,login);

    }
    @RequestMapping(value = "/updateContract",method = RequestMethod.POST)
    @ApiOperation(value = "修改",notes = "管理层修改合同",httpMethod = "POST",response = ResultJson.class)
    public ResultJson update(@RequestBody
        @ApiParam(name = "contract",value = "修改合同")
         Contract contract){

        System.out.println("修改合同");
        System.out.println(contract.getContract_number());
        System.out.println(contract.getTotle_money());
        return  contractService.updateContract(contract);
    }

    @RequestMapping(value = "/deleteByIDContract",method = RequestMethod.POST)
    @ApiOperation(value = "删除（修改状态）",notes = "管理层删除合同",httpMethod = "POST",response = ResultJson.class)
    public  ResultJson deleteById(@RequestParam  Integer id){
        System.out.println(id);
        return  contractService.deleteByIdContract(id);
    }
}
